﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Entities;
namespace Repository
{
    public class SqlDataReaderToEntity
    {
        public static User DataReaderToUser(SqlDataReader dr)
        {
            Entities.User model = new Entities.User();
            if (dr != null)
            {
                if (dr["ID"] != null)
                {
                    model.ID = dr["ID"].ToString();
                }
                if (dr["UserName"] != null)
                {
                    model.UserName = dr["UserName"].ToString();
                }
                if (dr["Password"] != null)
                {
                    model.Password = dr["Password"].ToString();
                }
                if (dr["Phone"] != null)
                {
                    model.Phone = dr["Phone"].ToString();
                }
                if (dr["Email"] != null)
                {
                    model.Email = dr["Email"].ToString();
                }
                if (dr["Creator"] != null)
                {
                    model.Creator = dr["Creator"].ToString();
                }
                if (dr["CreateTime"] != null && dr["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(dr["CreateTime"].ToString());
                }
                if (dr["Updator"] != null)
                {
                    model.Updator = dr["Updator"].ToString();
                }
                if (dr["UpdateTime"] != null && dr["UpdateTime"].ToString() != "")
                {
                    model.UpdateTime = DateTime.Parse(dr["UpdateTime"].ToString());
                }
                if (dr["Enabled"] != null && dr["Enabled"].ToString() != "")
                {
                    if ((dr["Enabled"].ToString() == "1") || (dr["Enabled"].ToString().ToLower() == "true"))
                    {
                        model.Enabled = true;
                    }
                    else
                    {
                        model.Enabled = false;
                    }
                }
                if (dr["Remark"] != null)
                {
                    model.Remark = dr["Remark"].ToString();
                }
            }
            return model;
        }

       public static Role DataReaderToRole(SqlDataReader dr)
        {
            Entities.Role model = new Entities.Role();
            if (dr != null)
            {
                if (dr["ID"] != null)
                {
                    model.ID = dr["ID"].ToString();
                }
                if (dr["Name"] != null)
                {
                    model.Name = dr["Name"].ToString();
                }
                if (dr["Description"] != null)
                {
                    model.Description = dr["Description"].ToString();
                }
                if (dr["Creator"] != null)
                {
                    model.Creator = dr["Creator"].ToString();
                }
                if (dr["CreateTime"] != null && dr["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(dr["CreateTime"].ToString());
                }
                if (dr["Updator"] != null)
                {
                    model.Updator = dr["Updator"].ToString();
                }
                if (dr["UpdateTime"] != null && dr["UpdateTime"].ToString() != "")
                {
                    model.UpdateTime = DateTime.Parse(dr["UpdateTime"].ToString());
                }
                if (dr["Enabled"] != null && dr["Enabled"].ToString() != "")
                {
                    if ((dr["Enabled"].ToString() == "1") || (dr["Enabled"].ToString().ToLower() == "true"))
                    {
                        model.Enabled = true;
                    }
                    else
                    {
                        model.Enabled = false;
                    }
                }
                if (dr["Remark"] != null)
                {
                    model.Remark = dr["Remark"].ToString();
                }
            }
            return model;
        }
    }
}
